#include "StdAfx.h"
#include "cln_rtt_handler.h"
namespace fly {

	namespace jld{

		namespace client {	

			cln_rtt_handler::cln_rtt_handler(bool is_test)
				:cln_handler(is_test)
			{

			}

			bool cln_rtt_handler::handle_recv(recv_buf& recv_buf, send_buf& send_buf, cln_info& info)
			{
				if (RTT != recv_buf.pid())
				{
					return cln_handler::handle_recv(recv_buf, send_buf, info);
				}
				LOG_INFO("Handle rtt");
				RoundTripTime rtt;
				recv_buf.parse_from_recv(rtt);
				if (!is_test_)
				{
					LOG_DEBUG("Untest rtt");
					return true;
				}
				if (rtt.is_proof())
				{
					rtt.set_cln_time(timestamp->cur_mill_sec());
					return send_buf.serialize_to_send(RTT, target_, rtt);
				}
				LOG_DEBUG("Set sync time");
				info.set_sync_time(rtt.rtt(), rtt.delta_time());
				return true;
			}
		}
	}
}